

$(document).ready(function(){

    $("#back").click(function(){
        window.location.href = "courier-login.html";
    })

    let id =  $.cookie('courierId');
    console.log(id);
    if(id==null || id==""){
        layer.msg("请先登录")
    }
    let page_cookie = $.cookie('page_cookie');
    let status_cookie = $.cookie('status_cookie');  
     
    function WaitNum(num){
        let htmlinfo = ''
           
                htmlinfo += `
                <span class="WaitNum">`+num+`</span>
             `
            
            $("#WaitNum").html(htmlinfo)
    }

    $('#gradding').click(function(){
        $("#pages").empty();
        let status = "已下单";
        layer.msg("正在查询")
      
        gradding(1,status)

        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#complete").removeClass("check");
           
        }     
    })
    
    function gradding(curr,status){
        
        if(curr==null){
            curr = 1;
        }
        status = "已下单"
        // $.cookie('status_cookie',status);
        // $.cookie('page_cookie',curr);
        $.ajax({
            url: url + "/courier/grabbing",
            async: false,
            dataType: "json",
            type: "post",
            data : {
                id:id,
                status:status,
                pageNum:curr
            },
            success: function (data) {
                console.log(data)
                pageAll();
               
                if(1 == data.code){
                layer.msg("查询成功")
                let list = data.data.list
                tableCome(list);
                information(list);


                layui.use(['laypage', 'layer'], function () {
                    var laypage = layui.laypage;
                    var layer = layui.layer;
                    laypage.render({
                        elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
                        , count:data.data.total //'{$total[count]}' //数据总数，从服务端得到
                        , theme: '#E5342A'
                        , curr: data.data.pageNum
                        , layout: ['count', 'prev', 'page', 'next', 'skip']
                        , limit: data.data.pageSize //每页数据量             
                        , jump: function (data, first) {
                            var curr = data.curr
                            var limit = data.limit

                            if (!first) {
                                gradding(curr,"已下单")
                            }
                        }
                    });
                });



                }else if(2 == data.code){
                    layer.msg("查询结果为空")
                }


            }
        }, "json")

        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#complete").removeClass("check");
           
        }     
    }

    //pageAll();
   function pick(curr,status){
       
        status="待上门"
        if(curr==null){
            curr = 1;
        }
        $.cookie('status_cookie',status);
        $.cookie('page_cookie',curr);
        $.ajax({
            url: url + "/courier/grabbing",
            
            dataType: "json",
            type: "post",
            
            data : {
                status:status,
                id:id,
                pageNum:curr
            },
            success: function (data) {
                if(1 == data.code){
                layer.msg("查询成功")
                let list = data.data.list
                tablePay(list);
                information(list);

                layui.use(['laypage', 'layer'], function () {
                    var laypage = layui.laypage;
                    var layer = layui.layer;                 
                    laypage.render({
                        elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
                        , count:data.data.total //'{$total[count]}' //数据总数，从服务端得到
                        , theme: '#E5342A'
                        , curr: data.data.pageNum
                        , layout: ['count', 'prev', 'page', 'next', 'skip']
                        , limit: data.data.pageSize //每页数据量
        
                        // ,limits:[10,20,30]
        
                        , jump: function (data, first) {
                        
                            var curr = data.curr
                            var limit = data.limit
                            
        
                            if (!first) {
                                pick(curr,"待上门")
        

        
                            }
                        }
        
                    });
                    
                });

                }else if(2 == data.code){
                    layer.msg("查询结果为空")
                }
            }
        }, "json") 
        
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#gradding").removeClass("check");
            $("#service").removeClass("check");
            $("#complete").removeClass("check");
        
        }     
    }
           
    $('#pick').click(function(){
        $("#pages").empty();
        layer.msg("正在查询")
       
        let status = "待上门";
       
        pick(1,status)
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#gradding").removeClass("check");
            $("#service").removeClass("check");
            $("#complete").removeClass("check");
        
        }     
    })

    
    
    function service(curr){ 
        let status ="待送达"
        layer.msg("正在查询")
        $.cookie('status_cookie',status);
        $.cookie('page_cookie',curr);
        $.ajax({
            url: url + "/courier/grabbing",
            async: false,
            dataType: "json",
            type: "post",
            data : {
                id:id,
                pageNum:curr,
                status:status
            },
            success: function (data) {
               
                if(1 == data.code){
                layer.msg("查询成功")
                let list = data.data.list
                tableWait(list);
                information(list);
                
                layui.use(['laypage', 'layer'], function () {
                    var laypage = layui.laypage;
                    var layer = layui.layer;
        
                 
                    
                    laypage.render({
                        elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
                        , count:data.data.total //'{$total[count]}' //数据总数，从服务端得到
                        , theme: '#E5342A'
                        , curr: data.data.pageNum
                        , layout: ['count', 'prev', 'page', 'next', 'skip']
                        , limit: data.data.pageSize //每页数据量
        
                        // ,limits:[10,20,30]
        
                        , jump: function (data, first) {
                          
                            var curr = data.curr
                            var limit = data.limit
                           
        
                            if (!first) {
                                service(curr)
        

        
                            }
                        }
        
                    });
                    
                });


                }else if(2 == data.code){
                    layer.msg("查询结果为空")
                }
            }
        }, "json")
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#gradding").removeClass("check");
            $("#complete").removeClass("check");
           
        }     
    }

    function layuiPage(data,curr){
       
       
        var laypage = layui.laypage;
        var layer = layui.layer;
        
      
        

        laypage.render({
            elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
            , count:data.data.total //'{$total[count]}' //数据总数，从服务端得到
            , theme: '#E5342A'
            , curr:curr
            , layout: ['count', 'prev', 'page', 'next', 'skip']
            , limit: data.data.pageSize //每页数据量

            // ,limits:[10,20,30]

            , jump: function (obj, first) {

                var curr = obj.curr
                var limit = obj.limit


                if (!first) {
                    layuiPage(data,curr)
                }
            }

        });
                
            
    }

    function layuiCur(data,curr){
       
       
        var laypage = layui.laypage;
        var layer = layui.layer;
      
        

        laypage.render({
            elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
            , count:data.data.total //'{$total[count]}' //数据总数，从服务端得到
            , theme: '#E5342A'
            , curr: data.data.pageNum
            , layout: ['count', 'prev', 'page', 'next', 'skip']
            , limit: data.data.pageSize //每页数据量

            // ,limits:[10,20,30]

            , jump: function (obj, first) {
                
                var curr = obj.curr
                var limit = obj.limit


                if (!first) {
                    layuiCur(data,curr)
                }
            }

        });
                
            
    }

   
                
            
    

    
    
    

    $('#service').click(function(){ 
        layer.msg("正在查询")
      
        
        service(1)
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#gradding").removeClass("check");
            $("#complete").removeClass("check");
           
        }     
    })

    

   


    function complete(curr){ 
        
        layer.msg("正在查询")
        let status = "已完成";
        $.cookie('status_cookie',status);
        $.cookie('page_cookie',curr);
        $.ajax({
            url: url + "/courier/grabbing",
            async: false,
            dataType: "json",
            type: "post",
            data : {
                id:id,
                pageNum:curr,
                status:status
            },
            success: function (data) {
               
                if(1 == data.code){
                layer.msg("查询成功")
                let list = data.data.list
                tableHistory(list);
                information(list);
                
                layui.use(['laypage', 'layer'], function () {
                    var laypage = layui.laypage;
                    var layer = layui.layer;
                    laypage.render({
                        elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
                        , count:data.data.total //'{$total[count]}' //数据总数，从服务端得到
                        , theme: '#E5342A'
                        , curr: data.data.pageNum
                        , layout: ['count', 'prev', 'page', 'next', 'skip']
                        , limit: data.data.pageSize //每页数据量
                        , jump: function (data, first) {
                            var curr = data.curr
                            var limit = data.limit
                            if (!first) {
                                complete(curr)
                                
                            }
                        }
                    });
                });


                }else if(2 == data.code){
                    layer.msg("查询结果为空")
                }
            }
        }, "json")

        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#gradding").removeClass("check");
           
        }     
    }

    $('#complete').click(function(){ 
        layer.msg("正在查询")
        complete(1);
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#gradding").removeClass("check");
           
        }     
    })


    // $(".tips").find("p").eq(3).html(htmlNum);

    $(document).on("click",".showPage",function(){

        // <span class="sendAddress">`+list[i].sendDetail+`</span>
        // <span class="createTime">`+list[i].createTime+`</span>
        // <span class="pageCode">`+list[i].pageCode+`</span>
        // <span class="pageId">`+list[i].pageId+`</span>
        // <span class="pageNum">`+list[i].pageNum+`</span>
        // <span class="pageType">`+list[i].pageType+`</span>
        // <span class="receiveAddress">`+list[i].receiveDetail+`</span>
        // <span class="receiveArea">`+list[i].receiveArea+`</span>
        // <span class="receiveCity">`+list[i].receiveCity+`</span>
        // <span class="receiveId">`+list[i].receiveId+`</span>
        // <span class="receiveName">`+list[i].receiveName+`</span>
        // <span class="receivePhone">`+list[i].receivePhone+`</span>
        // <span class="receiveProvince">`+list[i].receiveProvince+`</span>
        // <span class="receiveUserId">`+list[i].receiveUserId+`</span>
        // <span class="remark">`+list[i].remark+`</span>
        // <span class="remarkText">`+list[i].remarkText+`</span>
        // <span class="remarksTip">`+list[i].remarksTip+`</spanc>
        
        // <span class="sendArea">`+list[i].sendArea+`</span>
        // <span class="sendCity">`+list[i].sendCity+`</span>
        // <span class="sendId">`+list[i].sendId+`</span>
        // <span class="sendName">`+list[i].sendName+`</span>
        // <span class="sendPhone">`+list[i].sendPhone+`</span>
        // <span class="sendProvince">`+list[i].sendProvince+`</span>
        // <span class="sendUserId">`+list[i].sendUserId+`</span>
        // <span class="status">`+list[i].status+`</span>
        // <span class="updateTime">`+list[i].updateTime+`</span>
        // <span class="weight">`+list[i].weight+`</span>
        // <span class="money">`+list[i].money+`</span>

        let index = $(".div-page .showPage").index(this);
      

        let pageId = $(".none").find(".information").eq(index).find(".pagId").text();

        let pageNum = $(".none").find(".information").eq(index).find(".pageNum").text();
        

        let sendName = $(".none").find(".information").eq(index).find(".sendName").text();
        let sendPhone = $(".none").find(".information").eq(index).find(".sendPhone").text();
        let sendProvince = $(".none").find(".information").eq(index).find(".sendProvince").text();
        let sendCity = $(".none").find(".information").eq(index).find(".sendCity").text();
        let sendArea = $(".none").find(".information").eq(index).find(".sendArea").text();
        let sendDetail = $(".none").find(".information").eq(index).find(".sendDetail").text();

        let receiveName = $(".none").find(".information").eq(index).find(".receiveName").text();
        let receivePhone = $(".none").find(".information").eq(index).find(".receivePhone").text();
        let receiveProvince = $(".none").find(".information").eq(index).find(".receiveProvince").text();
        let receiveCity = $(".none").find(".information").eq(index).find(".receiveCity").text();
        let receiveArea = $(".none").find(".information").eq(index).find(".receiveArea").text();
        let receiveDetail = $(".none").find(".information").eq(index).find(".receiveDetail").text();

        let status = $(".none").find(".information").eq(index).find(".status").text();
        let remark = $(".none").find(".information").eq(index).find(".remark").text();
        let weight = $(".none").find(".information").eq(index).find(".weight").text();
        let createTime = $(".none").find(".information").eq(index).find(".createTime").text();

        let money = $(".none").find(".information").eq(index).find(".money").text();
        
        if(remark == null || remark == "null"){
            remark = "无"
        }

        let htmlConfirm =`
            <p>快递编号:`+pageNum+`</p>
            <p>寄件人姓名:`+sendName+`</p> 
            <p>寄件人联系方式:`+sendPhone+`</p> 
            <span>寄件人省市区:`+sendProvince+`<span> 
            <span>`+sendCity+`</span> 
          
            <p>寄件人详细地址:`+sendArea+`</p> 
            <p>收件人姓名:`+receiveName+`</p> 
            <p>收件人联系方式:`+receivePhone+`</p> 
            <span>收件人省市区:`+receiveProvince+`</span> 
            <span>`+receiveCity+`</span> 
         
            <p>收件人详细地址:`+receiveArea+`</p> 
            <p>快递当前状态:`+status+`</p> 
            <p>备注:`+remark+`</p> 
            <p>快递重量:`+weight+`kg</p> 
            <p>寄件人应付金额:`+money+`.00元</p> 
            <p>创建时间:`+createTime+`</p>       
        `
        if(status == "已下单"){
            layer.confirm(htmlConfirm, {
            btn: ['立即抢单','取消'] //按钮
        }, function(){
            let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
            let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
            layer.confirm('您确定要接受<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               
                let status = "待上门";
               
                $.ajax({
                    url: url + "/courier/courierUpdate",
                    async: false,
                    dataType: "json",
                    type: "post",
                    data : {
                        id:id,
                        status:status,
                        pageId:pageId
                    },
                    success: function (data) {
                      
                        if(1 == data.code){
                            pageAll()
                            gradding()
                            layer.msg('抢单成功', {icon: 1});
                        }else if(2 == data.code){
                            layer.msg('抢单失败', {icon: 2});
                        }
                    }
            }, "json")

            }, function(){
                // layer.msg('也可以这样', {
                //   time: 20000, //20s后自动关闭
                //   btn: ['明白了', '知道了']
                // });
            });

       
        },function(){
            
        });
        }

        if(status == "待上门"){
            layer.confirm(htmlConfirm, {
            btn: ['寄件付款','放弃订单','取消'] //按钮
        }, function(){
            
           
            let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
            let weight =$(".none").find(".information").eq(index).find(".weight").text();
            let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
            let sendName =$(".none").find(".information").eq(index).find(".sendName").text();
            let sendPhone =$(".none").find(".information").eq(index).find(".sendPhone").text();
            let sendAdress =$(".none").find(".information").eq(index).find(".sendAdress").text();
            let money =$(".none").find(".information").eq(index).find(".money").text();
            // // let status = "待取件";
           
          
            //let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
            //let status = "已完成";
            //let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
    
            layer.confirm('是否邀请寄件人为<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单付款', {
                btn: ['确定','取消'] //按钮
            }, function(){
                url = "./pay.html?sendPhone="+sendPhone+"&money="+money+"&status="+status+"&sendAdress="+sendAdress+"&pageId="+pageId+"&weight="+weight+"&pageNum="+pageNum+"&sendPhone="+sendName+"&sendName="+sendName;//此处拼接内容
                window.location.href = url;
                
           
            }, function(){});
      
        }, function(){
           
            let pageId =$(".none").find(".information").eq(index).find(".pageId").text();

            let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();

            layer.confirm('您确定要取消<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                
                let status = "已下单";
              
                $.ajax({
                    url: url + "/courier/courierUpdate",
                    async: false,
                    dataType: "json",
                    type: "post",
                    async: false,
                    data : {
                        id:id,
                        status:status,
                        pageId:pageId
                    },
                    success: function (data) {
                      
                        if(1 == data.code){
                            pageAll()
                            pick()
                            layer.msg("取消成功")
                        }else if(1 == data.code){
                            
                        }
                    }
                }, "json")
            }, function(){
                // layer.msg('也可以这样', {
                //   time: 20000, //20s后自动关闭
                //   btn: ['明白了', '知道了']
                // });
            });
       
        },function(){
            
            
      
        });
        }

        if(status == "待送达"){
            layer.confirm(htmlConfirm, {
            btn: ['确认送达','取消'] //按钮
        }, function(){

          
            let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
            let status = "已完成";
            let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
            let money =$(".none").find(".information").eq(index).find(".money").text();
         
            layer.confirm('是否提交<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                let status = "已完成";
                $.ajax({
                    url: url + "/courier/courierUpdate",
                    dataType: "json",
                    type: "post",
                    data : {
                        id:id,
                        status:status,
                        pageId:pageId,
                        money:money
                    },
                    success: function (data) {
                        if(1 == data.code){
                            pageAll()
                            service()
                            layer.msg('提交成功', {icon: 1});
                        }else if(2 == data.code){
                            layer.msg("查询结果为空")
                        }
                    }
                }, "json")
            }, function(){});
        },function(){

    
        });
    }

        if(status == "已完成"){

            layer.confirm(htmlConfirm, {
            btn: ['确定'] //按钮
        },function(){
            layer.close(layer.index);
        },function(){
            
        });
        }
    })

    $(document).on("click",".delete",function(){
        var index = $(".div-page .delete").index(this);
        let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
        
        let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();

        layer.confirm('您确定要取消<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单吗？', {
            btn: ['确定','取消'] //按钮
          }, function(){
         
            let status = "已下单";
          
            $.ajax({
                url: url + "/courier/courierUpdate",
                async: false,
                dataType: "json",
                type: "post",
                async: false,
                data : {
                    id:id,
                    status:status,
                    pageId:pageId
                },
                success: function (data) {
                  
                    if(1 == data.code){
                        pageAll()
                        pick()
                        layer.msg("取消成功")
                    }else if(1 == data.code){
                        
                    }
                }
            }, "json")
          }, function(){
            // layer.msg('也可以这样', {
            //   time: 20000, //20s后自动关闭
            //   btn: ['明白了', '知道了']
            // });
          });
    })

    $(document).on("click",".commit",function(){
       
        var index = $(".div-page .commit").index(this);
        let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
        let status = "已完成";
        let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
        let money =$(".none").find(".information").eq(index).find(".money").text();
      
        layer.confirm('是否提交<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单吗？', {
            btn: ['确定','取消'] //按钮
          }, function(){
         
            let status = "已完成";
           
            $.ajax({
                url: url + "/courier/courierUpdate",
                dataType: "json",
                type: "post",
                data : {
                    id:id,
                    status:status,
                    pageId:pageId,
                    money:money
                },
                success: function (data) {
                 
                    if(1 == data.code){
                        pageAll()
                        service()
                        layer.msg('提交成功', {icon: 1});
                    }else if(2 == data.code){
                        layer.msg("查询结果为空")
                    }
                }
            }, "json")
       
          }, function(){});
    });

    


        

    $(document).on("click",".pay",function(){
       
        var index = $(".div-page .pay").index(this);
        let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
        let weight =$(".none").find(".information").eq(index).find(".weight").text();
        let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
        let sendName =$(".none").find(".information").eq(index).find(".sendName").text();
        let sendPhone =$(".none").find(".information").eq(index).find(".sendPhone").text();
        let sendAdress =$(".none").find(".information").eq(index).find(".sendAdress").text();
        let money =$(".none").find(".information").eq(index).find(".money").text();
       
        layer.confirm('是否邀请寄件人为<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单付款', {
            btn: ['确定','取消'] //按钮
        }, function(){
            
            url = "./page-delivery-changeAddress.html?sendPhone="+sendPhone+"&money="+money+"&status="+status+"&sendAdress="+sendAdress+"&pageId="+pageId+"&weight="+weight+"&pageNum="+pageNum+"&sendPhone="+sendName+"&sendName="+sendName;//此处拼接内容
            window.location.href = url;
            
       
        }, function(){});
       
    });

    $(document).on("click",".showMap",function(){
       
        var index = $(".div-page .showMap").index(this);
        let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
        let weight =$(".none").find(".information").eq(index).find(".weight").text();
        let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
        let sendName =$(".none").find(".information").eq(index).find(".sendName").text();
        let sendPhone =$(".none").find(".information").eq(index).find(".sendPhone").text();
        let sendAdress =$(".none").find(".information").eq(index).find(".sendCity").text();
        let sendCity =$(".none").find(".information").eq(index).find(".sendCity").text();
        let sendArea =$(".none").find(".information").eq(index).find(".sendArea").text();
        let sendProvince =$(".none").find(".information").eq(index).find(".sendProvince").text();
        let money =$(".none").find(".information").eq(index).find(".money").text();
        let courierId =1;
        layer.confirm('即将查看<span style="font-weight:700">快递编号为'+pageNum+'</span>的地图定位，请确认GPS是否开启。', {
            btn: ['确定','取消'] //按钮
        }, function(){
            
            url = "./courier-map.html?;pageNum="+pageNum+"&courierId="+courierId;
            window.location.href = url;
            
       
        }, function(){});
       
    });
    

    $(document).on("click",".come",function(){
        var index = $(".div-page .come").index(this);
        let pageId =$(".none").find(".information").eq(index).find(".pageId").text();
        let pageNum =$(".none").find(".information").eq(index).find(".pageNum").text();
        layer.confirm('您确定要接受<span style="font-weight:700">快递编号为'+pageNum+'</span>的订单吗？', {
            btn: ['确定','取消'] //按钮
          }, function(){
            
            let status = "待上门";
            $.ajax({
                url: url + "/courier/courierUpdate",
                async: false,
                dataType: "json",
                type: "post",
                data : {
                    id:id,
                    status:status,
                    pageId:pageId
                },
                success: function (data) {
                   
                    if(1 == data.code){
                        pageAll()
                        gradding()
                        layer.msg('抢单成功', {icon: 1});
                    }else if(2 == data.code){
                        layer.msg('抢单失败', {icon: 2});
                    }
                }
            }, "json")
          }, function(){
           
          });
    })



    $('#showPage').click(function(){ 
        if($(this).hasClass("check")){

        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#gradding").removeClass("check");
           
        }     
    })

    function gx(){
        let status = "已下单";
        $.ajax({
            url: url + "/courier/grabbingNew",
            async: false,
            dataType: "json",
            type: "post",
            data : {
                id:id,
                status:status,
            },
            success: function (data) {

                if(1 == data.code){

                    if(data.data.length>0){
                        $(".talk").show();
                        $("#newPage").show();
                    }
                }else if(2 == data.code){
                    console.log(data);
                    $(".talk").hide();
                    $("#newPage").hide();
                }
            }
        }, "json")
    }

    window.setInterval(gx,3000);



    $('#come').click(function(){ 
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#gradding").removeClass("check");
           
        }     
    })

    $('#pay').click(function(){ 
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#gradding").removeClass("check");
           
        }     
    })

    $('#delete1').click(function(){ 
        let statusDelete ="已下单"
        let pageNum = "123"
        layer.open({
            title: '付款成功'
            ,content:  url
        });    
        
        
            
        $.ajax({
            url: url + "/courier/courierUpdate",
            async: false,
            dataType: "json",
            type: "post",
            data : {
                id:id,
                status:statusDelete,
                pageNum:pageNum
            },
            success: function (data) {
                if(1 == data.code){
                    layer.msg("取消成功")
                }
                            
            }
        }, "json")  
    })
    $(".tips").find("").eq(3).click(function(){ 
        if($(this).hasClass("check")){       
        }
        else{
            $(this).addClass("check");
            $("#pick").removeClass("check");
            $("#service").removeClass("check");
            $("#gradding").removeClass("check");
           
        }     
    })
    function Now(courierId){
        status = "已下单";   
    }
    function refresh(curr){
        
    }
    gradding();
    function pageAll(){
       
        status = "已下单";
        $.ajax({
            url: url + "/courier/grabbing",
            async: false,
            dataType: "json",
            type: "post",
            async: false,
            data : {
                id:id,
                status:status
            },
            success: function (data) {
              
                if(1 == data.code){
                
                let list = data.data.list
                let html = ``
                let htmlNum = `待抢单(`+data.data.total+`)` 
             
                $(".tips").find("span").eq(0).html(htmlNum);
                let num = data.data.total
                let htmlinfo = ''
           
                htmlinfo += `
                <span class="WaitNum">`+num+`</span>
             `
            $("#WaitNum").html(htmlinfo)

                }else if(2 == data.code){
                    
                }
            }
        }, "json")
        status = "待上门";
        $.ajax({
            
            url: url + "/courier/grabbing",
            async: false,
            dataType: "json",
            type: "post",
            async: false,
            data : {
                id:id,
                status:status
            },
            success: function (data) {
              
                if(1 == data.code){
                
                let list = data.data.list
                let html = ``
                let htmlNum = `待上门(`+data.data.total+`)` 
               
                $(".tips").find("span").eq(1).html(htmlNum);
                let num = data.data.total
                let htmlinfo = ''
                let htmlFinish = data.data.total+`单`
                $("#wait-finish").text(htmlFinish);
           
                htmlinfo += `
                <span class="WaitNum">`+num+`</span>
             `
            
            $("#WaitNum").html(htmlinfo)

                }else if(2 == data.code){
                    
                }
            }
        }, "json")
        console.log(id)
        $.ajax({
            
            url: url + "/courier/courierInCome",
            async: false,
            dataType: "json",
            type: "post",
            async: false,
            data : {
                id:id,
                status:status
            },
            success: function (data) {
              
                if(1 == data.code){
                
                let list = data.data
                let html = ``
                let htmlNum = data.data+`.00元` 
             
                $("#income").text(htmlNum);
                

                }else if(2 == data.code){
                    
                }
            }
        }, "json")

        status = "待送达";
    
        $.ajax({
            
            url: url + "/courier/grabbing",
            async: false,
            dataType: "json",
            type: "post",
            async: false,
            data : {
                id:id,
                status:status
            },
            success: function (data) {
            
                if(1 == data.code){
                
                let list = data.data.list
                let html = ``
                let htmlNum = `待送达(`+data.data.total+`)` 
             
                $(".tips").find("span").eq(2).html(htmlNum);
                let num = data.data.total
                let htmlinfo = ''
           
                htmlinfo += `
                <span class="WaitNum">`+num+`</span>
                 `
            
                $("#finishNum").html(htmlinfo)

                }else if(2 == data.code){
                    
                }
            }
        }, "json")

        status = "已完成";
     
        $.ajax({
            url: url + "/courier/grabbing",
            async: false,
            dataType: "json",
            type: "post",
            async: false,
            data : {
                id:id,
                status:status
            },
            success: function (data) {
             
                if(1 == data.code){
                
                let list = data.data.list
                let html = ``
                let htmlNum = `已完成(`+data.data.total+`)` 
                let htmlFinish = data.data.total+`单` 
           

                $("#finsihTwo").text(htmlFinish);
                    $(".tips").find("span").eq(3).html(htmlNum);
                }else if(2 == data.code){
                }
            }
        }, "json")
        
        

        let finisth1 = $(".finishNum").text();
        let WaitNum = $("waitGrabbing").text();
        console.log(finisth1)
        console.log(WaitNum)
        // $("#wait-finish").text(finisth1+WaitNum)

    }
        
        function tableCome(list){
            let html = ``
            for(let i = 0; i< list.length;i++){
                html += `
                <div class="div-table">
                <div class="page-text">
                编号:`+list[i].pageNum+`&nbsp;`+list[i].sendName+`<br>
                `+list[i].sendCity+``+list[i].sendDetail+`<br>
                `+list[i].createTime+`
                    `+list[i].money+`.00元<br>
                    
                </div>
                
                <button class="div-table-bt showPage"   type="button">查看详情</button>
                <button class="div-table-bt showMap"  type="button">定位地图</button>
                </div>
                `
            }
            $("#div-page").html(html)
        }

        function tablePay(list){
            let html = ``
            for(let i = 0; i< list.length;i++){
                html += `
                <div class="div-table">
                <div class="page-text">
                编号:`+list[i].pageNum+`&nbsp;`+list[i].sendName+`<br>
                `+list[i].sendCity+``+list[i].sendDetail+`<br>
                `+list[i].createTime+`
                    `+list[i].money+`.00元<br>
                    
                </div>
                
                <button class="div-table-bt showPage"   type="button">查看详情</button>
                <button class="div-table-bt delete"  type="button">取消订单</button>
              
                </div>
                `
            }
            $("#div-page").html(html)
        }

        function tableWait(list){
            let html = ``
            for(let i = 0; i< list.length;i++){
                html += `
                <div class="div-table">
                <div class="page-text">
                编号:`+list[i].pageNum+`&nbsp;`+list[i].sendName+`<br>
                `+list[i].sendCity+``+list[i].sendDetail+`<br>
                `+list[i].createTime+`
                `+list[i].money+`.00元<br>
                    
                </div>
                
                <button class="div-table-bt showPage"   type="button">查看详情</button>
                <button class="div-table-bt commit"  type="button">确认送达</button>
                </div>
                `
            }
            $("#div-page").html(html)
        }

        function tableHistory(list){
            let html = ``
            for(let i = 0; i< list.length;i++){
                html += `
                <div class="div-table">
                <div class="page-text">
                    编号:`+list[i].pageNum+`&nbsp;`+list[i].sendName+`<br>
                    `+list[i].sendCity+``+list[i].sendDetail+`<br>
                    `+list[i].createTime+`
                    `+list[i].money+`.00元<br>
                    
                </div>
                
                <button class="div-table-bt showPage"   type="button">查看详情</button>
                </div>
                `
            }
            $("#div-page").html(html)
        }

        function information(list){
            let htmlinfo = ''
                for(let i = 0; i< list.length;i++){
                   
                    htmlinfo += `
                    <div class="information">
                        <span class="sendAddress">`+list[i].sendDetail+`</span><br>
                        <span class="createTime">`+list[i].createTime+`</span><br>
                        <span class="pageCode">`+list[i].pageCode+`</span><br>
                        <span class="pageId">`+list[i].pageId+`</span><br>
                        <span class="pageNum">`+list[i].pageNum+`</span><br>
                        <span class="pageType">`+list[i].pageType+`</span><br>
                        <span class="receiveAddress">`+list[i].receiveDetail+`</span><br>
                        <span class="receiveArea">`+list[i].receiveArea+`</span><br>
                        <span class="receiveCity">`+list[i].receiveCity+`</span><br>
                        <span class="receiveId">`+list[i].receiveId+`</span><br>
                        <span class="receiveName">`+list[i].receiveName+`</span><br>
                        <span class="receivePhone">`+list[i].receivePhone+`</span><br>
                        <span class="receiveProvince">`+list[i].receiveProvince+`</span><br>
                        <span class="receiveUserId">`+list[i].receiveUserId+`</span><br>
                        <span class="remark">`+list[i].remark+`</span><br>
                        <span class="remarkText">`+list[i].remarkText+`</span><br>
                        <span class="remarksTip">`+list[i].remarksTip+`</spanc><br>
                       
                        <span class="sendArea">`+list[i].sendArea+`</span><br>
                        <span class="sendCity">`+list[i].sendCity+`</span><br>
                        <span class="sendId">`+list[i].sendId+`</span><br>
                        <span class="sendName">`+list[i].sendName+`</span><br>
                        <span class="sendPhone">`+list[i].sendPhone+`</span><br>
                        <span class="sendProvince">`+list[i].sendProvince+`</span><br>
                        <span class="sendUserId">`+list[i].sendUserId+`</span><br>
                        <span class="status">`+list[i].status+`</span><br>
                        <span class="updateTime">`+list[i].updateTime+`</span><br>
                        <span class="weight">`+list[i].weight+`</span><br>
                        <span class="money">`+list[i].money+`</span><br>

                        
                        
                    </div>
                    `
                }
                
                $(".none").html(htmlinfo)
        }


        


        UrlParam = function() { // url参数
            var data, index;    
            (function init() {    
              data = [];    //值，如[["1","2"],["zhangsan"],["lisi"]]
              index = {};   //键:索引，如{a:0,b:1,c:2}
              var u = window.location.search.substr(1);    
              if (u != '') {    
                var params = decodeURIComponent(u).split('&');
                for (var i = 0, len = params.length; i < len; i++) {
                  if (params[i] != '') {
                    var p = params[i].split("=");
                    if (p.length == 1 || (p.length == 2 && p[1] == '')) {// p | p= | =
                      data.push(['']);    
                      index[p[0]] = data.length - 1;    
                    } else if (typeof(p[0]) == 'undefined' || p[0] == '') { // =c 舍弃
                      continue;
                    } else if (typeof(index[p[0]]) == 'undefined') { // c=aaa    
                      data.push([p[1]]);    
                      index[p[0]] = data.length - 1;    
                    } else {// c=aaa    
                      data[index[p[0]]].push(p[1]);    
                    }    
                  }    
                }    
              }    
            })();    
            return {    
              // 获得参数,类似request.getParameter()    
              param : function(o) { // o: 参数名或者参数次序
                try {    
                  return (typeof(o) == 'number' ? data[o][0] : data[index[o]][0]);    
                } catch (e) {    
                }    
              },    
              //获得参数组, 类似request.getParameterValues()    
              paramValues : function(o) { //  o: 参数名或者参数次序
                try {    
                  return (typeof(o) == 'number' ? data[o] : data[index[o]]);    
                } catch (e) {}    
              },    
              //是否含有paramName参数
              hasParam : function(paramName) {
                return typeof(paramName) == 'string' ? typeof(index[paramName]) != 'undefined' : false;
              },    
              // 获得参数Map ,类似request.getParameterMap()    
              paramMap : function() {
                var map = {};    
                try {    
                  for (var p in index) {  map[p] = data[index[p]];  }    
                } catch (e) {}    
                return map;    
              }    
            }    
          }();
          
          let pageNumSuccess = UrlParam.param("pageNumSuccess");
       
          if(null != pageNumSuccess){
            let totalAmount = UrlParam.param("totalAmount");
            layer.msg('快递单号为'+pageNumSuccess+'的订单'+totalAmount+'元，付款成功', {icon: 1});

            setTimeout(function(){window.location.href="http://localhost:8085/courier/html/rush-delivery.html"},2000);
            
          }
         
});